// // class类写法
// class Students{
//     name:string;
//     age:number;
//     sex:string;
//     hobby?:string;
//     constructor(name:string, age:number, sex:string,hobby?:string){
//         this.name = name;
//         this.age = age;
//         this.sex = sex;
//         this.hobby = hobby;
//     };
//     // 原型对象上的属性或方法
//     say(x:string):string{//原型对象上的属性和方法在prototype上可以访问到
//         return this.name + x;
//     };
//     //实例对象自身的属性或方法
//     static color = 'pink';//在prototype的constructor上
//     static eat(y:string):string{
//         return this.name + y;
//     }
// }
// let tom = new Students('tom',18,'男');
// console.log(tom.say('hello'));
// console.log(Students.eat('kfc'));
// console.log(tom);
// // class类继承 extends super
// class Lily extends Students{
//     weight:string;
//     constructor(name:string, age:number,sex:string,weight:string){
//         super(name,age,sex);
//         this.weight = weight;
//     };
//     say(x: string): string {
//         return super.say(x);//继承父类原型方法
//     };
//     static color = super.color;//继承父类的自身属性
// }
// let rose = new Lily('rose',14,'女','160');
// console.log(rose);
// // 设置接口
// interface Type{
//     Child():any;
//     Hobby():string,
//     Age():number
// }
// class Test implements Type{
//     Child() {
//         return 1234;
//     };
//     Hobby(){
//         return '唱歌跳舞';
//     };
//     Age(): number {
//         return 819;
//     }
// }
// let uu = new Test();
// console.log(uu.Child());
// console.log(uu.Age());
// console.log(uu.Hobby());
// // 接口继承
// interface test1{
//     name:string;
// }
// interface test2{
//     age:number
// }
// interface test3 extends test1,test2{};
// // class Tru implements test1,test2{
// //     name = 'lily';
// //     age = 18
// // }
// class Tru implements test3{
//     name = 'lily';
//     age = 19;
// }
// let iu = new Tru;
// console.log(iu);
// // 访问修饰符
// // public 默认值, 公开的外部也可以访问
// // private 只能类内部可以访问
// // protected 类内部和子类可以访问
// class People{
//     public name:string;
//     private age:number;
//     protected sex:string;
//     constructor(name:string,age:number,sex:string){
//         this.name = name;
//         this.age = age;
//         this.sex = sex;
//     };
//     hobby():string{
//         console.log(this.age);
//         console.log(this.sex);
//         return this.name;
//     }
// }
// let IU = new People('李知恩',18,'女');
// // IU.hobby('唱歌');
// console.log(IU.name);
// // console.log(IU.age);
// console.log(IU.hobby());
// class Tests extends People {
//     constructor(name:string,age:number,sex:string){
//         super(name,age,sex);
//     };
//     hobby(): string {
//         console.log(this.sex);
//         return super.hobby();
//     }
// }
// let testtt = new Tests('rose',12,'女');
// console.log(testtt.hobby());
// class类ts写法
class Students{
    name:string;
    age:number;
    sex:string;
    hobby?:string;//该属性可写可不写
    constructor(name:string,age:number,sex:string,hobby?:string){
        this.name = name,
        this.age = age,
        this.sex = sex,
        this.hobby = hobby
    };
    say(x:string):string{//原型对象上的属性和方法
        console.log(x);
        return this.name + x;
    };
    static color = 'pink';//students自身的属性或方法
}
let lily = new Students('Lily',18,'女','唱歌跳舞');
console.log(lily);
console.log(lily.say('好想发财'));
// 继承
class StudentsChild extends Students{
    constructor(name:string,age:number,sex:string,hobby?:string){
        super(name,age,sex,hobby);
    };
    say(x:string):any{
        super.say(x);//students实例对象的属性或方法的继承语法
    };
    static color = super.color;//students自身的属性或方法的继承语法
}
let tom = new StudentsChild('tom',17,'男');
console.log(tom);
console.log(tom.say('hello'));
// 修饰符 public private protected
// 参数属性
class Test{
    constructor(public name:string,readonly age:number){//在参数前加修饰符就不用提前类型声明了
        this.name = name;
        this.age = age;
    }   
}
let test = new Test('test',10);
console.log(test);
// 抽象类 abstract
abstract class Info{//不能生成实例对象 只是用来被继承的
    abstract say();//方法属性都不可以写详细 只能模糊的写
}
class stuinfo extends Info{
    say() {
        console.log('暴富暴瘦');//具体写在继承的子类里
    }
}
let ceshi = new stuinfo();
ceshi.say();
// 存取器 get set
class Cuncu{
    constructor(public name:string,readonly age:number) {
        this.name = name;
        this.age = age;
    };
    get say(){
        return this.name + this.age;
    };
    set say(value){
        console.log(value);
    }
}
let cuncu  = new Cuncu('tom',18);
cuncu.say = '啦啦啦';
console.log(cuncu);
// 函数的写法
// 两种：①函数表达式②函数声明
// 函数表达式
function fun(x:string,y:number):string{
    return x + y;
};
console.log(fun('asd',4));
// 函数声明
let foo = function(a:string,b:string):string{
    return a + b;
};
console.log(foo('dfg','sdfgj'));
// 完整写法
let Foo:(a:string,b:string)=>string = function(a:string = 'iu',b:string = '接收的返回'):string{
    return a + b ;
}
console.log(Foo('圣诞节返回','就说的废话就'));
// 函数重载
// 已知数据类型
function boo(a:string,b:string):string;
function boo(a:number,b:number):number;
function boo(a:string|number,b:string|number){
    if(typeof a === 'string' && typeof b === 'string'){
        return a + b ;
    }else if(typeof a === 'number' && typeof b === 'number'){
        return a + b;
    }
}
console.log(boo('sdjhf','sdjfh'));
console.log(boo(1,5));
// 泛型
function cest<T>(a:T,b:T):T[]{
    return [a,b]
};
console.log(cest<string>('话费还是个','接收的返回'));
console.log(cest<number>(23,56));
console.log(cest<boolean>(true,false));
console.log(cest<object>({name:'lily'},{name:'jack'}))
// 泛型 元祖
function cat<T,K>(a:T,b:K):[T,K]{
    return [a,b]
};
console.log(cat<string,number>('圣诞节回复',12));
console.log(cat<boolean,number>(false,819))
export{
    lily,
    tom,
    test,
    ceshi
}